//
//  SHTradingQueryDateHeader.m
//  JiFengDaRen
//
//  Created by SH_iOS on 2017/10/23.
//  Copyright © 2017年 SH_iOS. All rights reserved.
//
#import "SHTradingDateControl.h"
#import "SHTradingQueryDateHeader.h"
@interface SHTradingQueryDateHeader()
@property(nonatomic,strong)SHTradingDateControl *beginDateView;
@property(nonatomic,strong)SHTradingDateControl *endDateView;


@end
@implementation SHTradingQueryDateHeader

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self  = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self.beginDateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(self);
            make.width.equalTo(@(KScreenWidth/2));
        }];
        
        [self.endDateView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.equalTo(self);
            make.width.equalTo(@(KScreenWidth/2));

        }];
        
       
       
        
        UIView *lineView = [[UIView alloc]init];
        lineView.backgroundColor = KLINECOLOR;
        [self addSubview:lineView];
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.centerY.equalTo(self);
            make.width.equalTo(@0.5);
            make.height.equalTo(@(__I6Height(55)));

            
        }];
    }
    
    return self;
}

- (SHTradingDateControl *)beginDateView{
    
    if (!_beginDateView) {
        
        _beginDateView = [[SHTradingDateControl alloc]initWithFrame:CGRectZero];
        [_beginDateView setTradingDateName:@"起始时间"];
        [_beginDateView addTarget:self action:@selector(getBeginDateAction:) forControlEvents:UIControlEventTouchUpInside];

        [_beginDateView setTradingDate:[self getCurrentDate]];
        [self addSubview:_beginDateView];
    }
    
    return _beginDateView;
}

- (SHTradingDateControl *)endDateView{
    
    if (!_endDateView) {
        _endDateView = [[SHTradingDateControl alloc]initWithFrame:CGRectZero];
        [_endDateView setTradingDateName:@"结束时间"];
        [_endDateView addTarget:self action:@selector(getEndDateAction:) forControlEvents:UIControlEventTouchUpInside];
        [_endDateView updateSubViewsConstraints];
        [_endDateView setTradingDate:[self getCurrentDate]];
        [self addSubview:_endDateView];

    }
    
    return _endDateView;
}

#pragma mark - 获取今日时间
- (NSString *)getCurrentDate{
    
    //起时间按钮
    NSDate *currentDate = [NSDate date];//获取当前时间，日期
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSString *dateString = [dateFormatter stringFromDate:currentDate];
    return dateString;
}


#pragma mark - 获取开始时间
- (void)getBeginDateAction:(SHTradingDateControl *)control{
    
    if ([_delegate respondsToSelector:@selector(tradingQueryDateHeader:dateControl: tag:)]) {
        
        [_delegate tradingQueryDateHeader:self dateControl:control tag:1];
    }
    
}

#pragma mark - 获取结束时间时间
- (void)getEndDateAction:(SHTradingDateControl *)control{
    
    if ([_delegate respondsToSelector:@selector(tradingQueryDateHeader:dateControl: tag:)]) {
        
        [_delegate tradingQueryDateHeader:self dateControl:control tag:2];
    }
    
}

#pragma mark - 开始时间
- (void)setBenginDate:(NSString *)benginDate{
    
    [_beginDateView setTradingDate:benginDate];

}

#pragma mark -
- (void)setEndDate:(NSString *)endDate{
    
    [_endDateView setTradingDate:endDate];
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
